package cn.wolfcode.controller;

import cn.wolfcode.domain.InMsgEntity;
import cn.wolfcode.domain.OutMsgEntity;
import cn.wolfcode.service.IWebChatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class WebChatController {

    @Autowired
    private IWebChatService webChatService;

    /**
     * URL接入校验
     * signature	微信加密签名，signature结合了开发者填写的token参数和请求中的timestamp参数、nonce参数。
     * timestamp	时间戳
     * nonce	随机数
     * echostr	随机字符串
     */
    @GetMapping(value = "webChat")
    @ResponseBody
    public String validate(String signature,String timestamp,String nonce,String echostr) {
        // 请原样返回echostr参数内容,则接入生效,成为开发者成功,否则失败
        System.out.println("接入失败");
        return echostr;
    }

    @PostMapping("/webChat")
    public OutMsgEntity handelMassage(@RequestBody InMsgEntity inMsgEntity){
        OutMsgEntity outMsgEntity = webChatService.handelMsg(inMsgEntity);
        return outMsgEntity;
    }
}